<%@ page import="java.util.HashMap,common.CommonUtil,java.util.*,common.*,java.text.*" contentType="text/html; charset=utf-8" %>
<%@ taglib uri="/WEB-INF/commontags.tld" prefix="common" %><%--페이징처리tag--%>
<%
UserSession userSession = (UserSession)session.getAttribute("user"); 

String site_url = request.getServerName().replace("http://","");

String login_id = null;
String user_id = null;
String level = null;

if(userSession!= null){
	login_id = userSession.getLogin_id();
	user_id = userSession.getUser_id();
	level = userSession.getAdmin_level();
}


String s_test_gubun = CommonUtil.nvl(request.getParameter("s_test_gubun"),"");

String s_member_dist = CommonUtil.nvl(request.getParameter("s_member_dist"),"");
String s_rater = CommonUtil.nvl(request.getParameter("s_rater"),"");
String s_rating_state 	= CommonUtil.nvl(request.getParameter("rating_state"),"");

String search_combo 	= CommonUtil.nvl(request.getParameter("search_combo"),"");
String keyword 		= CommonUtil.nvl(request.getParameter("keyword"),"");
String line_number	= CommonUtil.nvl(request.getParameter("line_number"),"10");
//페이징 처리 Start
//페이지 표시정보 받기 혹은 검색입력창
String curr_page = CommonUtil.nvl(request.getParameter("curr_page"),"1");

String one_group = CommonUtil.nvl(request.getParameter("one_group"),"10");
String total_count = CommonUtil.nvl(request.getParameter("total_count"),"0");
//페이징 처리 End

String start_date	= CommonUtil.nvl(request.getParameter("start_date"),""); 
String end_date	= CommonUtil.nvl(request.getParameter("end_date"),"");
SimpleDateFormat tf = new SimpleDateFormat ("yyyy-MM-dd");
Calendar sday =new GregorianCalendar();
sday.set(Integer.parseInt(CommonUtil.getToday("yyyy")), Integer.parseInt(CommonUtil.getToday("MM"))-2, Integer.parseInt(CommonUtil.getToday("dd")));

if(start_date.equals("")){
	start_date = tf.format(sday.getTime());
}

if(end_date.equals("")){
	end_date = CommonUtil.getToday("yyyy")+"-"+CommonUtil.getToday("MM")+"-"+CommonUtil.getToday("dd");
}

String[] start_date_arr = start_date.split("-");
String[] end_date_arr = end_date.split("-");

HashMap listMap=(HashMap)request.getAttribute("list_map");

HashMap map  = null;
ArrayList list=null;

HashMap map_1  = null;
ArrayList list_1=null;

String member_test_code 		= "";
String member_id 		= "";
String test_state 		= "";
String reg_dt 	= "";
String login_id_map 		= "";
String login_name 	= "";
String email	= "";
String cell_no	= "";
String result_code	= "";

String rater_id	= "";
String rating_state	= "";
String rating_start_time	= "";
String rating_close_time	= "";
String rating_reg_dt	= "";
String rater_name 	= "";

String rerating_member_test_code	= "";
String rerating_gubun	= "";
String rerating_reason	= "";

String r_num="";

String sign_code="";
String link_id="";

String end_dt="";
String member_dist_str="";

String cd = "";
String cd_nm = "";

String bg_color = "";

String result_view_yn = "";

if (listMap!=null){
    list=(ArrayList)listMap.get("mainContent");
    list_1=(ArrayList)listMap.get("mainContent_1");
}

if(list != null){
	if(list.size() > 0){
		total_count = (String)((HashMap)list.get(0)).get("total_row");
		System.out.println("total_count ========> " + total_count);
	}
}

if(list.size() == 0){
	total_count = "0";
}

%>
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script language='javascript' src="/js/calendar.js"></script>
<script>

//xml 요청
function getXMLHTTPRequest() {
try {
  req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    } 
  } 
}
return req;
}


function get_rater_give_request(mc,ri,si,li){
  
  var http = getXMLHTTPRequest();
  var myurl = '/speaking.pb?gubun=opic&cmd=rater_give&member_test_code='+mc+'&rater_id='+ri+'&pay_code='+si+'&link_id='+li+'&test_state=2&rating_state=1';
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"&rand="+myRand;  
  http.open("get", modurl, false);
  //http.onreadystatechange = useHttpResponse;
  http.send(null);
  if (http.readyState == 4) {
    return trim(http.responseText);
  }else{
   return "";
  }
} 	

function trim(str){
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}

function get_rater_chk(mc,ri,si,li){
	var frm = document.mainform;
	
	if(!confirm('Allocate?')){
		return;
	}
	
	if(ri == ''){
		alert('Rater Select');		
	}
	var rater_chk = get_rater_give_request(mc,ri,si,li);
	
	alert('Allocate.');
	var page = frm.curr_page.value ;
	go_page(page)	;
	/*
	if(trim(rater_chk)=='OK'){
		
		alert('Allocate.');
		var page = frm.curr_page.value ;
		go_page(page)	;		
		
	}else{
		alert('problem');
	}
	*/
}



function go_result(ad){
	var frm = document.mainform;
	frm.member_test_code.value= ad;
	
	var popw = 870;
	var poph = 700
	
	var popleft = (screen.width - popw)/2;
	var poptop = (screen.height - poph)/2;
	
	var open_opictest = window.open('','opicresult','width='+popw+',height='+poph+',resizable=no,scrollbars=yes,top='+poptop+',left='+popleft);
	open_opictest.focus();
	
	<%if(!site_url.equals("solution.dkeol.com")){ %>
	var do_str=document.domain;
	var v_str = do_str.split('.');
	var s_str='';
	for (i=1;i<v_str.length;i++){
		if (i!=1){
			s_str+='.';
		}
		s_str+=v_str[i];
	}	
	s_str = 'dev.'+s_str;
	<%}else{ %>
	var s_str=document.domain;
	<%} %>
	
	frm.cmd.value='opictest_result';
	//frm.action = '/speaking.pb';
	var url = 'http://'+s_str+'/opictest_result.jsp';
	frm.action = url;
		
	frm.target= 'opicresult';              
	frm.submit();	
	
	
	frm.action = '';
	frm.target= '';     
}


function go_select(ad,ri){
	var frm = document.mainform;
	
	if(frm.user_id.value == ri || frm.level.value == '1' || ri==''){
		frm.member_test_code.value= ad
		frm.cmd.value='opictest_select';
		frm.action = '/speaking.pb';
		frm.target= '_self';              
		frm.submit();	
	}else{
		alert('Non authority.');
	}
}

function go_delete(ad){
	var frm = document.mainform;
	if(confirm('삭제하시겠습니까?')){
	frm.member_test_code.value= ad
	frm.cmd.value='opictest_delete';
	frm.action = '/speaking.pb';
	frm.target= 'hidden_frm';              
	frm.submit();
	}
}


function go_opictest(){
	var frm = document.mainform;	
	frm.cmd.value='opictest_main';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();	
}

//검색
function go_search(){
	var frm = document.mainform;
	/*
	if(frm.search_combo.value==''){
		alert('검색구분을 선택하세요.');
		return;
	}
	*/
	frm.cmd.value='opictest_main';
	frm.curr_page.value ="1";
	frm.total_count.value="0";
	frm.action = "/speaking.pb";
	frm.target="_self";
	frm.submit();
}

// 페이지 번호를 눌렸을때.
function go_page(page){
	var frm = document.mainform;
	frm.cmd.value='opictest_main';
	frm.curr_page.value = page ;			
	frm.total_count.value = "<%=total_count%>";
	frm.keyword.value = "<%=keyword%>";
	frm.action = "/speaking.pb";
	frm.target="_self";
	frm.submit();
}

function go_excel(){
	var frm = document.mainform;	
	//frm.cmd.value='member_main';
	frm.action = '/jsp/sp_sp0301_excel.jsp';
	frm.target= 'hidden_frm';              
	frm.submit();	
}
</script>

<jsp:include page="/jsp/common/top.jsp"></jsp:include>
<jsp:include page="/jsp/common/submenu.jsp"><jsp:param name="submenu_id" value="opictest_main" /><jsp:param name="submenu_idx" value="1" /></jsp:include>

<form name="mainform"  method="post" action = "/speaking.pb" >
	<div id="bodyContainer">
        <div id="contents">
          <jsp:include page="/jsp/common/submenu_list.jsp"><jsp:param name="submenu_id" value="opictest_main" /><jsp:param name="submenu_idx" value="1" /></jsp:include>
          <div class="select_menu">
          	<ul>              
              <li >
              	<select name="s_test_gubun" id="s_test_gubun" style="width:100px" onchange="go_search()">
                  <option value=''>Date Select</option>
                  <option value='T' <%=(s_test_gubun.equals("T")?"selected":"") %>>Date of Test </option>
                  <option value='R' <%=(s_test_gubun.equals("R")?"selected":"") %>>Rating of Test </option>
                </select>  
              </li> 
              
              <li style="padding-top:7px">Start Date :</li>
              <li ><INPUT TYPE="text" style="width:70px" NAME="start_date"  id="start_date" value="<%=start_date %>" OnFocus=cal(<%=start_date_arr[0] %>,<%=start_date_arr[1] %>,<%=start_date_arr[2] %>,this);></li>
              <li style="padding-top:7px">~</li>
			  <li style="padding-top:7px">End Date :</li>             
              <li ><INPUT TYPE="text" style="width:70px"  NAME="end_date"  id="end_date" value="<%=end_date %>" OnFocus=cal(<%=end_date_arr[0] %>,<%=end_date_arr[1] %>,<%=end_date_arr[2] %>,this);></li>
            </ul>
          </div>
          <div class="select_menu">
          	<ul>
          	 
              <li >
              	<select name="s_member_dist" id="s_member_dist" style="width:100px" onchange="go_search()">
                  <option value=''>Member dist</option>
                  <option value='P' <%=(s_member_dist.equals("P")?"selected":"") %>>수강생</option>
                  <option value='B' <%=(s_member_dist.equals("B")?"selected":"") %>>B2C</option>
                </select> 
              </li>
              <li>  
                <select name="s_rater" id="s_rater" style="width:100px" >
                  <option value=''>Rater Select</option>
                <%
                if (list_1!=null && list_1.size()> 0) {
			    	for(int j=0; j<list_1.size(); j++){
				      map_1=(HashMap)list_1.get(j);
				      cd = CommonUtil.nvl((String)map_1.get("cd"));
				      cd_nm = CommonUtil.nvl((String)map_1.get("cd_nm"));
				
				%>		        
                  <option value="<%=cd %>" <%=(s_rater.equals(cd))?"selected":"" %>><%=cd_nm %></option>
                <%
			    	}
                }
                %>  
                </select> 
              </li>
              
            </ul>
          </div>
          <div class="select_menu">
            <ul>              
               <li><select name="rating_state" id="rating_state" style="width:100px">
                <option value=''>Rating Status</option>
                <option value=0 <%=(s_rating_state.equals("0"))?"selected":"" %>>Before Rating</option>
                <option value=1 <%=(s_rating_state.equals("1"))?"selected":"" %>>On Rating</option>
                <option value=2 <%=(s_rating_state.equals("2"))?"selected":"" %>>Finished Rating</option>
                <option value=9 <%=(s_rating_state.equals("9"))?"selected":"" %>>Unrating</option> 
                <option value=10 <%=(s_rating_state.equals("10"))?"selected":"" %>>Holding</option>
              </select></li>
              
              <li><select name="search_combo" id="search_combo">
                <option value=''>Select</option>
                <option value='1'>Name</option>
                <option value='2'>ID</option>
              </select></li>
              <li><input type="text" name="keyword" id="keyword" style="width:200px"/></li>
              <li><a href="#" onclick="go_search()"><img src="/img/btn_search.gif" alt="search" /></a></li>
              <li style="padding-left:380px"><a href="#" onclick="go_excel()"><img src="/img/btn_excel.gif" alt="excel" /></a></li>
            </ul>
          </div> 
          
          <div class="boxContainer">
            <dl title="Administration of OPIC Test">
              <dt>Administration of OPIC Test [Total : <font style="color:red"><%=total_count %></font>]</dt>
            </dl>
            <table class="listTb">
              <tr>
                <th width="30">Num</th>
                <th width="50">Name</th>
                <th width="50">ID</th>
                <th width="70">Phone<br>Number</th>
                <th width="90">Date of Test<br>(End of Test)</th>
                <th>Rating <Br>of Test</th>
                <th width="50">Rater</th>
                <th width="50">Status</th> 
                <th width="50">Results</th>
                <th width="50">Manage</th>                
              </tr>
<%               

    if (list!=null && list.size()> 0) {
    	for(int i=0; i<list.size(); i++){
	      map=(HashMap)list.get(i);
	      r_num = CommonUtil.nvl((String)map.get("r_num"));
	      member_test_code = CommonUtil.nvl((String)map.get("member_test_code"));
	      member_id = CommonUtil.nvl((String)map.get("member_id"));
	      login_id_map = CommonUtil.nvl(Crypto.DecodeBySType((String)map.get("login_id")));
	      login_name = CommonUtil.nvl((String)map.get("login_name"));
	      email = CommonUtil.nvl((String)map.get("email"));
	      cell_no = CommonUtil.nvl((String)map.get("cell_no"));
	      reg_dt = CommonUtil.nvl((String)map.get("reg_dt"));
	      
	      result_code = CommonUtil.nvl((String)map.get("result_code"));
	       
	      rater_id = CommonUtil.nvl((String)map.get("rater_id"));
	      rating_state = CommonUtil.nvl((String)map.get("rating_state"));
	      rating_start_time = CommonUtil.nvl((String)map.get("rating_start_time"));
	      rating_close_time = CommonUtil.nvl((String)map.get("rating_close_time"));
	      rating_reg_dt = CommonUtil.nvl((String)map.get("rating_reg_dt"));
	      rater_name = CommonUtil.nvl((String)map.get("rater_name"));
	      
	      rerating_member_test_code = CommonUtil.nvl((String)map.get("rerating_member_test_code"));
	      rerating_gubun = CommonUtil.nvl((String)map.get("rerating_gubun"));
	      rerating_reason = CommonUtil.nvl((String)map.get("rerating_reason"));
	      
	      sign_code = CommonUtil.nvl((String)map.get("sign_code"));
	      link_id = CommonUtil.nvl((String)map.get("link_id"));
	      
	      end_dt = CommonUtil.nvl((String)map.get("end_dt"));
	      member_dist_str = CommonUtil.nvl((String)map.get("member_dist_str"));
	      
	      result_view_yn = CommonUtil.nvl((String)map.get("result_view_yn"));
	      
	      /*
	      	test_state(시험할당,시험진행, 완료상태) 0,1,2
			rating_state(분배전,진행, 완료 상태,홀딩, 시작을 하던중 어떤이유로 완료를 못하면 같은 rater이 
			다시 클릭하면 다시 시작할수 있도록, 리스트에는 10분 이상이 지나면 상태 다르게 표시하기) 0,1,2,9(재시험)
			홀딩상태는 시험할당후 2일이 지난거를 홀딩으로만 표시..
			
			채점시작하면 다르사람 채점, 분배 안되도록...
			
			강사에게 분배시 셀렉트 박스에 지금 진행중인 갯수 보이도록 하기..
			
			할당받은 강사가 시험내역을 볼 경우 시험채점시작날짜 업데이트.. -> rater_state가 1인 경우에만 업데이트
	      */
	      bg_color = "";
		  if(user_id.equals(rater_id)) bg_color = "#82b3ed";
		  
		  if(rater_id.equals("") && !rating_state.equals("2")) bg_color = "#ff87be";
	      
%>
			<tr >
                <td style="background-color:<%=bg_color %>"><%=r_num %></td>
                <td style="background-color:<%=bg_color %>"><%=login_name %>
                <%=(!member_dist_str.equals("")?"<br>("+member_dist_str+")":"") %></td>
                <td style="background-color:<%=bg_color %>"><%=login_id_map %>
                <%=(rerating_gubun.equals("1"))?"<br>(UnRating)":"" %>
                </td>
                <td style="background-color:<%=bg_color %>"><%=cell_no %></td>
                <td style="background-color:<%=bg_color %>"><%=reg_dt %>
                <%=(!end_dt.equals("")?"<br>("+end_dt+")":"") %></td>
                <td style="background-color:<%=bg_color %>"><%=rating_close_time %></td>
                
                <%if(level.equals("1") || level.equals("2")){ %>
                <%if(!rater_id.equals("") && !rating_state.equals("Holding") || rating_state.equals("2")){ %>
                <td style="background-color:<%=bg_color %>"><%=rater_name %></td>
                <%}else{ %>
                <td style="background-color:<%=bg_color %>"><select name="rater" id="rater" style="width:100px" onchange="get_rater_chk('<%=member_test_code %>',this.value,'<%=sign_code %>','<%=link_id %>')">
                  <option value=''>Rater Select</option>
                <%
                if (list_1!=null && list_1.size()> 0) {
			    	for(int j=0; j<list_1.size(); j++){
				      map_1=(HashMap)list_1.get(j);
				      cd = CommonUtil.nvl((String)map_1.get("cd"));
				      cd_nm = CommonUtil.nvl((String)map_1.get("cd_nm"));
				
				%>		        
                  <option value="<%=cd %>" <%=(rater_id.equals(cd))?"selected":"" %>><%=cd_nm %></option>
                <%
			    	}
                }
                %>  
                </select> <!-- <a href="#"><img src="img/btn_assign2.gif" alt="할당" border="0" align="middle" /></a> -->
                </td>
                
                <%} %>                
                <%}else{ %>
                <td style="background-color:<%=bg_color %>"><%=rater_name %></td>
                <%} %>
                
                <td style="background-color:<%=bg_color %>">
                <%if(rating_state.equals("1")){ %>
                <img src="img/btn_progress.gif" alt="진행중" border="0" />
                <%}else if (rating_state.equals("2")){%>
                <img src="img/btn_complete.gif" alt="완료" border="0" />
                <%}else if (rating_state.equals("9")){%>
                	 retest 
                	<!--<img src='img/btn_ready.gif' alt='레디' border="0" />-->
                <%}else if (rating_state.equals("Holding")){%>
                <img src="img/btn_holding.gif" alt="홀딩" border="0" />
                <%}else{ %>
                <img src='img/btn_ready.gif' alt='레디' border="0" />
                <%} %>
                </td>
                <td style="background-color:<%=bg_color %>"><%if(!result_code.equals("")){ %><a href='#' onclick="go_result('<%=member_test_code%>')"><b>Go Result (<%=(result_view_yn.equals("N"))?"N":"Y" %>)</b></a><%} %></td>
                <td style="background-color:<%=bg_color %>"><a href="#" onclick="go_select('<%=member_test_code%>','<%=rater_id%>')"><img src="img/btn_mmm.gif" width="16" height="14" alt="manage" /></a> 
                <%if(level.equals("1") || level.equals("2")){ %>
                <a href="#" onclick="go_delete('<%=member_test_code%>')"><img src="img/btn_ddd.gif" width="16" height="14" alt="delete" /></a>
                <%} %>
                </td>
              </tr>
<%	      
    	}
      
    }else{

%> 
    				<tr>
    	                <td colspan=10 align=center>Non List.</td>
    	            </tr>
<%
   }
%>
            </table>
            <!-- 
            	<a href="#"><img src="img/btn_ready.gif" alt="레디" border="0" /></a>
                <a href="#"><img src="img/btn_holding.gif" alt="홀딩" border="0" /></a>
                <a href="#"><img src="img/btn_progress.gif" alt="진행중" border="0" /></a>
                <a href="#"><img src="img/btn_complete.gif" alt="완료" border="0" /></a>
             -->
            <!-- 
            <div class="paging"><a href="#"><img src="img/bt_pprev.gif" alt="이전" /></a><a href="#"><img src="img/bt_prev.gif" alt="이전" /></a><a href="#" class="on">1</a><a href="#">2</a><a href="#">3</a><a href="#">4</a><a href="#">5</a><a href="#"><img src="img/bt_next.gif" alt="이전" /></a><a href="#"><img src="img/bt_nnext.gif" alt="이전" /></a></div>
             -->
            <!-- 페이징 -->
            <div class="paging"><common:pagelistnew currPage="<%=curr_page%>" total="<%=total_count%>" onePage="<%=line_number%>" oneGroup="<%=one_group%>"/></div>
            <!-- //페이징 -->
           
           <!-- 
            <p class="a_r"><a href="#" onclick="go_input()"><img src="img/btn_regist.gif" alt="등록" width="49" height="20" /></a>&nbsp;&nbsp; </p>
             -->
          </div>
          
        </div>
      </div>


<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="level" value="<%=level %>">
<input type="hidden" name="member_test_code" value="">
<input type="hidden" name="rater_id" value="">
<input type="hidden" name="line_number" value="<%=line_number%>">
<input type="hidden" name="curr_page" value="<%=curr_page%>">
<input type="hidden" name="total_count" value="<%=total_count%>"> 
</form>

<iframe name='hidden_frm'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
<jsp:include page="/jsp/common/footer.jsp"></jsp:include>
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
